<?php

	// +----------------------------------------------------------------------
	// | 模块模型
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\model\admin;

	class Module extends Common
	{
		// 非开放模块
		private $deny_module_list = [
			'common',
			'extra',
			'lang',
			'install',
		];

		/**
		 * 获取系统模块列表.
		 * @author 微尘 <yicmf@qq.com>
		 */
		public static function getAll()
		{
			return array_merge(['all' => '所有模块'], self::where('status', 1)->column('title', 'name'));
		}

		// 模块状态为3的不可操作
		// 获取器
		public function getStatusAttr($value, $data)
		{
			return 1 == $data['is_core'] ? 3 : $value;
		}

		/**
		 * 写入修改
		 * @param $data
		 */
		public static function onBeforeInsert($data)
		{
			$data['status'] = 1;
		}

		protected $type = [
			'need_app' => 'array',
		];
	}
